unit IniciaFechamentoCupomMFD;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Mask;

type
  TFormIniciaFechamentoCupomMFD = class(TForm)
    GBValor: TGroupBox;
    RB_DescontoValor: TRadioButton;
    RB_DescontoPercentual: TRadioButton;
    BitBtn1: TBitBtn;
    GBTIpo: TGroupBox;
    CBDesconto: TCheckBox;
    CBAcrescimo: TCheckBox;
    MaskEdit1: TMaskEdit;
    Label1: TLabel;
    Label2: TLabel;
    MaskEdit2: TMaskEdit;
    procedure RB_DescontoPercentualClick(Sender: TObject);
    procedure RB_DescontoValorClick(Sender: TObject);
    procedure CBDescontoClick(Sender: TObject);
    procedure CBAcrescimoClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormIniciaFechamentoCupomMFD: TFormIniciaFechamentoCupomMFD;

implementation

uses principal;

{$R *.dfm}

procedure TFormIniciaFechamentoCupomMFD.RB_DescontoPercentualClick(
  Sender: TObject);
begin
        if cbDesconto.Checked then begin
                MaskEdit1.MaxLength:=4;
                MaskEdit1.EditMask:='9999';
                MaskEdit1.Text:='1000';
        end;
        if cbACrescimo.Checked then begin
                MaskEdit2.MaxLength:=4;
                MaskEdit2.EditMask:='9999';
                MaskEdit2.Text:='1000';
        end;
end;

procedure TFormIniciaFechamentoCupomMFD.RB_DescontoValorClick(
  Sender: TObject);
begin
        if cbDesconto.Checked then begin
                MaskEdit1.MaxLength:=9;
                MaskEdit1.EditMask:='999999999999,99';
                MaskEdit1.Text:='000000000001,00';
        end;
        if cbAcrescimo.Checked then begin
                MaskEdit2.MaxLength:=9;
                MaskEdit2.EditMask:='999999999999,99';
                MaskEdit2.Text:='000000000001,00';
        end

end;

procedure TFormIniciaFechamentoCupomMFD.CBDescontoClick(Sender: TObject);
begin
        if CBDesconto.Checked Then MaskEdit1.Enabled:=True
        else MaskEdit1.Enabled:=False;
end;

procedure TFormIniciaFechamentoCupomMFD.CBAcrescimoClick(Sender: TObject);
begin
        if CBAcrescimo.Checked Then MaskEdit2.Enabled:=True
        else MaskEdit2.Enabled:=False;

end;

procedure TFormIniciaFechamentoCupomMFD.BitBtn1Click(Sender: TObject);
var valor:string;
begin

        valor:=Maskedit1.Text; virgula:=pos(',',valor);
        Delete(valor, virgula, 1);
        FormPrincipal.DescontoItem:=valor;

        valor:=Maskedit2.Text; virgula:=pos(',',valor);
        Delete(valor, virgula, 1);
        FormPrincipal.AcrescimoItem:=valor;

        if Rb_DescontoValor.checked then FormPrincipal.TipoDescontoItem:='$'
        else FormPrincipal.TipoDescontoItem:='%';
        if CBDesconto.checked and not CBAcrescimo.Checked then FormPrincipal.TipoDescontoAcrescimo:='D'
        else if not CBDesconto.checked and CBAcrescimo.Checked then FormPrincipal.TipoDescontoAcrescimo:='A'
        else if not CBDesconto.checked and CBAcrescimo.Checked then FormPrincipal.TipoDescontoAcrescimo:='A'
        else FormPrincipal.TipoDescontoAcrescimo:=#0;
        FormPrincipal.TipoDescontoAcrescimo:='A';

        Close;

end;

end.
